package com.herench.bs.handler;

import com.herench.bs.agent.IOutpatientClinicAgent;
import com.herench.bs.annotation.Handler;
import com.herench.bs.support.AbstractMessageHandler;
import com.herench.bs.support.RequestMessage;
import com.herench.bs.support.ResponseMessage;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.HashMap;
import java.util.Map;

/**
 * cleverClinic
 * com.herench.bs.handler
 *
 * @author wangwenkai
 * @date 2017/11/12/23:14
 */
@Component
@Handler(code = "102115" ,name="诊间支付结果通知(yibao)")
public class PayConfirmForClinicChargeInsuranceHandler extends AbstractMessageHandler {
    @Override
    protected ResponseMessage innerHandler(RequestMessage requestMessage) throws Exception {
        ResponseMessage responseMessage = new ResponseMessage(requestMessage.getId());
        String channelCode = requestMessage.getArgsPropertyStringValue("sysCode");
        String paySeq = requestMessage.getArgsPropertyStringValue("paySeq");
        Assert.notNull(paySeq, "paySeq 不可为空！");
        String orderId = requestMessage.getArgsPropertyStringValue("orderId");
        String userPersonId = requestMessage.getArgsPropertyStringValue("userPersonId");
        Assert.notNull(userPersonId, "userPersonId 不可为空！");
        String orderFee = requestMessage.getArgsPropertyStringValue("orderFee");
        Assert.notNull(orderFee, "orderFee 不可为空！");
        String payTime = requestMessage.getArgsPropertyStringValue("payTime");
        String tradeNo = requestMessage.getArgsPropertyStringValue("tradeNo");
        String openId = requestMessage.getArgsPropertyStringValue("openId");
        String patientId = requestMessage.getArgsPropertyStringValue("patientId");
        Assert.notNull(patientId, "patientId 不可为空！");
        String moneyPay = requestMessage.getArgsPropertyStringValue("moneyPay");
        //新增分割费用
        Map<String, Object> res = new HashMap<>(16);
        IOutpatientClinicAgent outpatientClinicAgent = getCleverClinicContext().getApplicationContext().getBean(IOutpatientClinicAgent.class);
        String hospitalCode = getCleverClinicContext().getHospitalCodeByChannelCode(channelCode);
        res = outpatientClinicAgent.payConfirmForClinicChargeInsurance(channelCode, hospitalCode, paySeq, openId, orderId, patientId, userPersonId, orderFee, payTime, tradeNo, moneyPay);
        responseMessage.setData(res);
        getPropertiesFromInvokerResultMap(responseMessage, res);
        return responseMessage;
    }
}

